package val.to.UI;

import val.to.R;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;

public class LocationChooser extends MapActivity
{
	MapController mc;
    GeoPoint p;

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.location_chooser);
	    
	    Intent i = getIntent();
	    int lon = i.getIntExtra("Lon", Integer.MAX_VALUE);
	    int lat = i.getIntExtra("Lat", Integer.MAX_VALUE);
	    
	    MapView mapView = (MapView) findViewById(R.id.mapview);
	    mapView.setBuiltInZoomControls(true);
	    
	    mc = mapView.getController();
        mc.setZoom(15);
        
        final MyLocationOverlay myLocation = new MyLocationOverlay(this, mapView);
        mapView.getOverlays().add(myLocation);
        myLocation.enableMyLocation();
        
        mapView.showContextMenu();
        
        Drawable drawable = this.getResources().getDrawable(R.drawable.bulbgrey4);        
        SelectedLocationOverlay itemOverlay = new SelectedLocationOverlay(drawable, this,true);
        
        if(lon < Integer.MAX_VALUE)
        {
        	p = new GeoPoint(lat,lon);
        	OverlayItem item = new OverlayItem(p, "", "");
        	itemOverlay.addOverlay(item);
        	mc.animateTo(p);
        	myLocation.disableMyLocation();
        }
        else
        {
        	myLocation.runOnFirstFix(new Runnable() {
                public void run() {
                    mc.animateTo(myLocation.getMyLocation());
                }
             });
        }
        
        mapView.getOverlays().add(itemOverlay);
        
        
        mapView.invalidate();
        
        
	}

	
}
